package com.walk.zworld.view.location

import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.walk.zworld.R
import com.walk.zworld.databinding.LocationItemSelectorAddressBinding
import com.walk.zworld.view.location.tenbean.TencentPoiModel

/**
 * @author KangYee
 * @description
 **/
class LocationSelectorAddressAdapter : BaseQuickAdapter<TencentPoiModel, BaseViewHolder>(
    R.layout.location_item_selector_address
), LoadMoreModule {

    private var activePosition = -1

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        // 绑定 view
        DataBindingUtil.bind<ViewDataBinding>(viewHolder.itemView)
    }

    override fun convert(holder: BaseViewHolder, item: TencentPoiModel) {
        val binding: LocationItemSelectorAddressBinding? = DataBindingUtil.getBinding(holder.itemView)
        binding?.let {
            it.model = item
            it.isCheck = holder.absoluteAdapterPosition == activePosition

            it.executePendingBindings()
        }
    }

    fun getActivePosition(): Int {
        return activePosition
    }

    fun setActivePosition(value: Int) {
        activePosition = value
        notifyDataSetChanged()
    }

}